home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 020a / dvpt20.zip / VPTEST.C < prev    next >
C/C++ Source or Header  |  1991-12-12  |  4KB  |  162 lines

  1. /****************************************************************/
  2. /*                                                              */
  3. /*             Digitized Voice Programmer's Toolkit             */
  4. /*             ------------------------------------             */
  5. /*                                                              */
  6. /*                     Playback example                         */
  7. /*                                                              */
  8. /*            Copyright (c) 1991, Farpoint Software             */
  9. /*                                                              */
  10. /****************************************************************/
  11.  
  12. #include "vpmod.h"
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <malloc.h>
  17. #include <fcntl.h>
  18. #include <io.h>
  19. #include <sys\types.h>
  20. #include <sys\stat.h>
  21. #include <bios.h>
  22. #include <string.h>
  23.  
  24. /*-------------------------------------------------------------------*/
  25.  
  26. char logo[] = "Digitized Voice Playback Test Program\r\n"
  27.  "Copyright(c) 1991, Farpoint Software\r\n";
  28.  
  29. char filename[128];        /* file containing voice data */
  30. char huge *buffer;         /* RAM buffer to hold file image */
  31. int handle;                /* handle of voice data file */
  32. long file_size;            /* size in bytes of voice data file */
  33.  
  34. /*-------------------------------------------------------------------*/
  35.  
  36. void main(argc, argv)
  37. int argc;
  38. char **argv;
  39.  
  40. {
  41. unsigned short sizelo, sizehi;   /* used to partition file load process */
  42. unsigned short i;
  43. char huge *loadptr;              /* 32 bit pointer used during loading */
  44. int delayctr;                    /* internal timing delay from PCALIBRATE */
  45. long byte_count;                 /* count of bytes played from PLAYVOICE */
  46. int calflag;                     /* status word returned from PCALIBRATE */
  47. long retval;
  48.  
  49. /* display the logo */
  50.  
  51. puts(logo);
  52.  
  53. /* check for one argument on command line */
  54.  
  55. if ( argc < 2 )
  56.     {
  57.     puts("Include file name on command line.");
  58.     exit(1);
  59.     }
  60.  
  61. argv++;
  62. strcpy(filename, *argv);
  63.  
  64. /* open the file */
  65.  
  66. handle = open(filename, O_BINARY|O_RDONLY);
  67. if ( handle == -1 )
  68.     {
  69.     puts("Error opening file.");
  70.     exit(1);
  71.     }
  72.  
  73. /* get the file length */
  74.  
  75. file_size = filelength(handle);
  76.  
  77. /* allocate memory for the buffer */
  78.  
  79. buffer = (char huge *)halloc(file_size,1);
  80. if ( buffer == NULL )
  81.     {
  82.     close(handle);
  83.     puts("Unable to allocate buffer memory.");
  84.     exit(1);
  85.     }
  86.  
  87. /* read the file into the buffer */
  88.  
  89. sizelo = (unsigned short)(file_size & 0x7FFFL);
  90. sizehi = (unsigned short)(file_size >> 15);
  91. loadptr = buffer;
  92. for ( i = 0 ; i < sizehi ; i++)
  93.     {
  94.     if ( 32768U != (unsigned)read(handle, loadptr, 32768U) )
  95.         {
  96.         close(handle);
  97.         hfree(buffer);
  98.         puts("File read error.");
  99.         exit(1);
  100.         }
  101.     loadptr += 32768;
  102.     }
  103. if ( sizelo )
  104.     {
  105.     if ( sizelo != (unsigned)read(handle, loadptr, sizelo) )
  106.         {
  107.         close(handle);
  108.         hfree(buffer);
  109.         puts("File read error.");
  110.         exit(1);
  111.         }
  112.     }
  113.  
  114. /* close the file */
  115.  
  116. close(handle);
  117.  
  118. /* calibrate for CPU speed */
  119.  
  120. puts("Calibrating...");
  121. retval = PCALIBRATE();
  122. calflag = (int)(retval & 0xFFFF);
  123. delayctr = (int)(retval >> 16);
  124. switch ( calflag )
  125.     {
  126.     case 1:
  127.         hfree(buffer);
  128.         puts("This computer is too slow to perform adequately with this program.");
  129.         printf("Speed rating = %d    Minimum = 64\n", delayctr);
  130.         exit(1);
  131.     case 2:
  132.         hfree(buffer);
  133.         puts("This program will not function properly under Enhanced-mode Microsoft Windows.");
  134.         exit(1);
  135.     case 3:
  136.         puts("Unusual speaker circuit detected; proper operation is uncertain.");
  137.         break;
  138.     }
  139. printf("delay counter = %d\n", delayctr);   /* to satisfy your curiosity */
  140.  
  141. /* tell user that we're getting ready */
  142.  
  143. puts("Press any key to stop.");
  144. puts("Starting...");
  145.  
  146. /* perform the playback */
  147.  
  148. byte_count = PLAYVOICE(buffer, file_size);
  149.  
  150. /* tell user that we're done */
  151.  
  152. puts("Done.");
  153.  
  154. /* show the number of bytes played */
  155.  
  156. printf("%ld bytes played.\n", byte_count);
  157.  
  158. /* free the allocated memory */
  159.  
  160. hfree(buffer);
  161. }
  162.